<?php
$this->title = '评论';
?>
<body class="m-add-comm">

<div class="desc f-cb">
    <?php if(!empty($data['product'])){?>
    <img src="/static/img/tmp003.jpg" />
    <div>
        <a href="javascript:;"><?= $data['product']['name']?></a>
        <?php if(!empty($data['product']['attributes'])){
            foreach($data['product']['attributes'] as $key => $val){
                if($key != 'product_id'){ ?>
                    <span><?= $key?>：<?= $val?></span>
                <?php }
            }
        }?>
        <b><?= $data['product']['price']?></b>
        <em>交易成功</em>
    </div>
    <?php } ?>
</div>

<dl class="tit f-cb"><dt>评价</dt><dd><span><em style="width:40%;"></em></span></dd></dl>

<div class="form">
    <textarea id="J_inputCnt" rows="6" placeholder="请输入反馈意见,我们会以消息"></textarea>
    <span>0 字</span>
</div>

<div class="upld">
    <h1>上传图片 <small>( 最多上传 3 张图片, 选填 )</small></h1>
    <p>
        <img src="/static/img/tmp005.jpg">
        <img src="/static/img/tmp005.jpg">
        <a class="m-upload-btn" href="javascript:;">
            <input type="file" onchange="upfile(this);" accept="image/jpg,image/jpeg,image/png,image/gif" multiple="multiple"><span>&nbsp;</span>
        </a>
    </p>

    <button type="submit" onclick="submit();">提交</button>
</div>

<script>
    $(function(){

        $('#J_inputCnt').on('keyup', function() {
            var _this = $(this);
            _this.next().text(_this.val().length + ' 字');
        });

        function upfile(ob){

            var dir = ob.value;
            if(dir.length <= 0) return !1;

            var ext = /\.[^\.]+$/.exec(dir)[0];

            if(ext !== '.jpg' || ext !== '.png' || ext !== '.gif'){
                console.log('格式错误');
                return !1;
            }

            // ......
        }

    });
    function submit()
    {
        var text = $('#J_inputCnt').val();
        var pid = <?= $data['product_id']?>;
        $.get("<?=\yii\helpers\Url::to(['add'])?>", {pid:pid, content:text}, function(data) {
            if(data == 1) {
                window.location.href = '/web/order';
            }else {
                alert(data);
            }
        })
    }
</script>
</body>